home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / src / gas-211 / gas / obj-form.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-26  |  64.5 KB  |  2,568 lines

  1. /* coff object file format with bfd
  2.    Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GAS.
  5.  
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GAS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GAS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /*
  21.  
  22.  How does this releate to the rest of GAS ?
  23.  
  24.  Well, all the other files in gas are more or less a black box. It
  25.  takes care of opening files, parsing command lines, stripping blanks
  26.  etc etc. This module gets a chance to register what it wants to do by
  27.  saying that it is interested in various pseduo ops. The other big
  28.  change is write_object_file. This runs through all the data
  29.  structures that gas builds, and outputs the file in the format of our
  30.  choice.
  31.  
  32.  Hacked for BFDness by steve chamberlain
  33.  
  34.  This object module now supports the Hitachi H8/{3|5}00 and the AMD 29k
  35.  
  36.  sac@cygnus.com
  37. */
  38.  
  39. #include "as.h"
  40. #include "obstack.h"
  41. #include "subsegs.h"
  42. #include "frags.h"
  43. #include "../bfd/libbfd.h"
  44. #include "../bfd/libcoff.h"
  45.  
  46. /* The NOP_OPCODE is for the alignment fill value.  Fill with nop so
  47.    that we can stick sections together without causing trouble.  */
  48. #ifndef NOP_OPCODE
  49. #define NOP_OPCODE 0x00
  50. #endif
  51.  
  52. #define MIN(a,b) ((a) < (b)? (a) : (b))
  53. /* This vector is used to turn an internal segment into a section #
  54.    suitable for insertion into a coff symbol table
  55.  */
  56.  
  57. const short seg_N_TYPE[] =
  58. {                /* in: segT   out: N_TYPE bits */
  59.   C_ABS_SECTION,
  60.   1,
  61.   2,
  62.   3,
  63.   4,
  64.   5,
  65.   6,
  66.   7,
  67.   8,
  68.   9,
  69.   10,
  70.   C_UNDEF_SECTION,        /* SEG_UNKNOWN */
  71.   C_UNDEF_SECTION,        /* SEG_ABSENT */
  72.   C_UNDEF_SECTION,        /* SEG_PASS1 */
  73.   C_UNDEF_SECTION,        /* SEG_GOOF */
  74.   C_UNDEF_SECTION,        /* SEG_BIG */
  75.   C_UNDEF_SECTION,        /* SEG_DIFFERENCE */
  76.   C_DEBUG_SECTION,        /* SEG_DEBUG */
  77.   C_NTV_SECTION,        /* SEG_NTV */
  78.   C_PTV_SECTION,        /* SEG_PTV */
  79.   C_REGISTER_SECTION,        /* SEG_REGISTER */
  80. };
  81.  
  82.  
  83. int function_lineoff = -1;    /* Offset in line#s where the last function
  84.                    started (the odd entry for line #0) */
  85.  
  86.  
  87. static symbolS *last_line_symbol;
  88.  
  89. /* Add 4 to the real value to get the index and compensate the
  90.    negatives. This vector is used by S_GET_SEGMENT to turn a coff
  91.    section number into a segment number
  92. */
  93. static symbolS *previous_file_symbol = NULL;
  94. void c_symbol_merge ();
  95. static int line_base;
  96.  
  97. symbolS *c_section_symbol ();
  98. bfd *abfd;
  99. void EXFUN (bfd_as_write_hook, (struct internal_filehdr *,
  100.                 bfd * abfd));
  101.  
  102. static void EXFUN (fixup_segment, (segment_info_type *segP,
  103.                    segT this_segment_type));
  104.  
  105.  
  106. static void EXFUN (fixup_mdeps, (fragS *,
  107.                  object_headers *,
  108.                  segT));
  109.  
  110.  
  111. static void EXFUN (fill_section, (bfd * abfd,
  112.                   object_headers *,
  113.                   unsigned long *));
  114.  
  115.  
  116. char *EXFUN (s_get_name, (symbolS * s));
  117. static symbolS *EXFUN (tag_find_or_make, (char *name));
  118. static symbolS *EXFUN (tag_find, (char *name));
  119.  
  120.  
  121. static int
  122.   EXFUN (c_line_new, (
  123.                symbolS * symbol,
  124.                long paddr,
  125.                unsigned short line_number,
  126.                fragS * frag));
  127.  
  128.  
  129. static void EXFUN (w_symbols,
  130.              (bfd * abfd,
  131.               char *where,
  132.               symbolS * symbol_rootP));
  133.  
  134.  
  135.  
  136. static void EXFUN (obj_coff_def, (int what));
  137. static void EXFUN (obj_coff_lcomm, (void));
  138. static void EXFUN (obj_coff_dim, (void));
  139. static void EXFUN (obj_coff_text, (void));
  140. static void EXFUN (obj_coff_data, (void));
  141. static void EXFUN( obj_coff_bss,(void));
  142. static void EXFUN( obj_coff_ident,(void));
  143. static void EXFUN (obj_coff_endef, (void));
  144. static void EXFUN (obj_coff_line, (void));
  145. static void EXFUN (obj_coff_ln, (void));
  146. static void EXFUN (obj_coff_scl, (void));
  147. static void EXFUN (obj_coff_size, (void));
  148. static void EXFUN (obj_coff_tag, (void));
  149. static void EXFUN (obj_coff_type, (void));
  150. static void EXFUN (obj_coff_val, (void));
  151. void EXFUN (obj_coff_section, (void));
  152. static void EXFUN (tag_init, (void));
  153. static void EXFUN (tag_insert, (char *name, symbolS * symbolP));
  154.  
  155.  
  156. static struct hash_control *tag_hash;
  157. static symbolS *def_symbol_in_progress = NULL;
  158.  
  159. const pseudo_typeS obj_pseudo_table[] =
  160. {
  161.   {"def", obj_coff_def, 0},
  162.   {"dim", obj_coff_dim, 0},
  163.   {"endef", obj_coff_endef, 0},
  164.   {"line", obj_coff_line, 0},
  165.   {"ln", obj_coff_ln, 0},
  166.   {"scl", obj_coff_scl, 0},
  167.   {"size", obj_coff_size, 0},
  168.   {"tag", obj_coff_tag, 0},
  169.   {"type", obj_coff_type, 0},
  170.   {"val", obj_coff_val, 0},
  171.   {"section", obj_coff_section, 0},
  172.   {"use", obj_coff_section, 0},
  173.   {"sect", obj_coff_section, 0},
  174.   {"text", obj_coff_text, 0},
  175.   {"data", obj_coff_data, 0},
  176.   {"bss", obj_coff_bss, 0},
  177.   {"ident", obj_coff_ident, 0},
  178.   {"ABORT", s_abort, 0},
  179.   {"lcomm", obj_coff_lcomm, 0},
  180.   {NULL}            /* end sentinel */
  181. };                /* obj_pseudo_table */
  182.  
  183.  
  184.  
  185. /* Section stuff
  186.  
  187.    We allow more than just the standard 3 sections, infact, we allow
  188.    10 sections, (though the usual three have to be there).
  189.  
  190.    This structure performs the mappings for us:
  191.  
  192. */
  193.  
  194. /* OBS stuff
  195. static struct internal_scnhdr bss_section_header;
  196. struct internal_scnhdr data_section_header;
  197. struct internal_scnhdr text_section_header;
  198.  
  199. const segT N_TYPE_seg [32] =
  200. {
  201.  
  202. };
  203.  
  204. */
  205.  
  206. #define N_SEG 32
  207. typedef struct
  208. {
  209.   segT seg_t;  
  210.   int i;  
  211. } seg_info_type;
  212.  
  213. seg_info_type seg_info_off_by_4[N_SEG] = 
  214. {
  215.  {SEG_PTV,  },
  216.  {SEG_NTV,  },
  217.  {SEG_DEBUG, },
  218.  {SEG_ABSOLUTE,  },
  219.  {SEG_UNKNOWN,     },
  220.  {SEG_E0}, 
  221.  {SEG_E1},
  222.  {SEG_E2},
  223.  {SEG_E3},
  224.  {SEG_E4},
  225.  {SEG_E5},
  226.  {SEG_E6},
  227.  {SEG_E7},
  228.  {SEG_E8}, 
  229.  {SEG_E9},
  230.  {(segT)15},
  231.  {(segT)16},
  232.  {(segT)17},
  233.  {(segT)18},
  234.  {(segT)19},
  235.  {(segT)20},
  236.  {(segT)0},
  237.  {(segT)0},
  238.  {(segT)0},
  239.  {SEG_REGISTER}
  240. };
  241.  
  242.  
  243.  
  244. #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
  245. #define SEG_INFO_FROM_SEG_NUMBER(x) (seg_info_off_by_4[(x)])
  246.  
  247.  
  248. relax_addressT
  249. DEFUN (relax_align, (address, alignment),
  250.        register relax_addressT address AND
  251.        register long alignment)
  252. {
  253.   relax_addressT mask;
  254.   relax_addressT new_address;
  255.  
  256.   mask = ~((~0) << alignment);
  257.   new_address = (address + mask) & (~mask);
  258.   return (new_address - address);
  259. }                /* relax_align() */
  260.  
  261.  
  262. segT
  263. DEFUN (s_get_segment, (x),
  264.        symbolS * x)
  265. {
  266.   return SEG_INFO_FROM_SECTION_NUMBER (x->sy_symbol.ost_entry.n_scnum).seg_t;
  267. }
  268.  
  269.  
  270.  
  271. /* calculate the size of the frag chain and fill in the section header
  272.    to contain all of it, also fill in the addr of the sections */
  273. static unsigned int
  274. DEFUN (size_section, (abfd, idx),
  275.        bfd * abfd AND
  276.        unsigned int idx)
  277. {
  278.  
  279.   unsigned int size = 0;
  280.   fragS *frag = segment_info[idx].frchainP->frch_root;
  281.   while (frag)
  282.     {
  283.       size = frag->fr_address;
  284.       if (frag->fr_address != size)
  285.     {
  286.       printf ("Out of step\n");
  287.       size = frag->fr_address;
  288.     }
  289.  
  290.       switch (frag->fr_type)
  291.     {
  292. #ifdef TC_COFF_SIZEMACHDEP
  293.     case rs_machine_dependent:
  294.       size += TC_COFF_SIZEMACHDEP (frag);
  295.       break;
  296. #endif
  297.     case rs_fill:
  298.     case rs_org:
  299.       size += frag->fr_fix;
  300.       size += frag->fr_offset * frag->fr_var;
  301.       break;
  302.     case rs_align:
  303.       size += frag->fr_fix;
  304.       size += relax_align (size, frag->fr_offset);
  305.     }
  306.       frag = frag->fr_next;
  307.     }
  308.   segment_info[idx].scnhdr.s_size = size;
  309.   return size;
  310. }
  311.  
  312.  
  313. static unsigned int
  314. DEFUN (count_entries_in_chain, (idx),
  315.        unsigned int idx)
  316. {
  317.   unsigned int nrelocs;
  318.   fixS *fixup_ptr;
  319.  
  320.   /* Count the relocations */
  321.   fixup_ptr = segment_info[idx].fix_root;
  322.   nrelocs = 0;
  323.   while (fixup_ptr != (fixS *) NULL)
  324.     {
  325.       if (TC_COUNT_RELOC (fixup_ptr))
  326.     {
  327.  
  328. #ifdef TC_A29K
  329.  
  330.       if (fixup_ptr->fx_r_type == RELOC_CONSTH)
  331.         nrelocs += 2;
  332.       else
  333.         nrelocs++;
  334. #else
  335.       nrelocs++;
  336. #endif
  337.     }
  338.  
  339.       fixup_ptr = fixup_ptr->fx_next;
  340.     }
  341.   return nrelocs;
  342. }
  343.  
  344. /* output all the relocations for a section */
  345. void
  346. DEFUN (do_relocs_for, (abfd, h, file_cursor),
  347.        bfd * abfd AND
  348.        object_headers * h AND
  349.        unsigned long *file_cursor)
  350. {
  351.   unsigned int nrelocs;
  352.   unsigned int idx;
  353.   unsigned long reloc_start = *file_cursor;
  354.  
  355.   for (idx = SEG_E0; idx < SEG_E9; idx++)
  356.     {
  357.       if (segment_info[idx].scnhdr.s_name[0])
  358.     {
  359.       struct external_reloc *ext_ptr;
  360.       struct external_reloc *external_reloc_vec;
  361.       unsigned int external_reloc_size;
  362.       unsigned int base = segment_info[idx].scnhdr.s_paddr;
  363.       fixS *fix_ptr = segment_info[idx].fix_root;
  364.       nrelocs = count_entries_in_chain (idx);
  365.  
  366.       if (nrelocs)
  367.         /* Bypass this stuff if no relocs.  This also incidentally
  368.            avoids a SCO bug, where free(malloc(0)) tends to crash.  */
  369.         {
  370.           external_reloc_size = nrelocs * RELSZ;
  371.           external_reloc_vec =
  372.         (struct external_reloc *) malloc (external_reloc_size);
  373.  
  374.           ext_ptr = external_reloc_vec;
  375.  
  376.           /* Fill in the internal coff style reloc struct from the
  377.          internal fix list.  */
  378.           while (fix_ptr)
  379.         {
  380.           symbolS *symbol_ptr;
  381.           struct internal_reloc intr;
  382.  
  383.           /* Only output some of the relocations */
  384.           if (TC_COUNT_RELOC (fix_ptr))
  385.             {
  386. #ifdef TC_RELOC_MANGLE
  387.               TC_RELOC_MANGLE (fix_ptr, &intr, base);
  388.  
  389. #else
  390.               symbolS *dot;
  391.               symbol_ptr = fix_ptr->fx_addsy;
  392.  
  393.               intr.r_type = TC_COFF_FIX2RTYPE (fix_ptr);
  394.               intr.r_vaddr =
  395.             base + fix_ptr->fx_frag->fr_address + fix_ptr->fx_where;
  396.  
  397.               intr.r_offset = fix_ptr->fx_offset;
  398.  
  399.               intr.r_offset = 0;
  400.  
  401.               /* Turn the segment of the symbol into an offset.  */
  402.               if (symbol_ptr)
  403.             {
  404.               dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
  405.               if (dot)
  406.                 {
  407.                   intr.r_symndx = dot->sy_number;
  408.                 }
  409.               else
  410.                 {
  411.                   intr.r_symndx = symbol_ptr->sy_number;
  412.                 }
  413.  
  414.             }
  415.               else
  416.             {
  417.               intr.r_symndx = -1;
  418.             }
  419. #endif
  420.  
  421.               (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
  422.               ext_ptr++;
  423.  
  424. #if defined(TC_A29K)
  425.  
  426.               /* The 29k has a special kludge for the high 16 bit
  427.              reloc.  Two relocations are emited, R_IHIHALF,
  428.              and R_IHCONST. The second one doesn't contain a
  429.              symbol, but uses the value for offset.  */
  430.  
  431.               if (intr.r_type == R_IHIHALF)
  432.             {
  433.               /* now emit the second bit */
  434.               intr.r_type = R_IHCONST;
  435.               intr.r_symndx = fix_ptr->fx_addnumber;
  436.               (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
  437.               ext_ptr++;
  438.             }
  439. #endif
  440.             }
  441.  
  442.           fix_ptr = fix_ptr->fx_next;
  443.         }
  444.  
  445.           /* Write out the reloc table */
  446.           bfd_write ((PTR) external_reloc_vec, 1, external_reloc_size,
  447.              abfd);
  448.           free (external_reloc_vec);
  449.  
  450.           /* Fill in section header info.  */
  451.           segment_info[idx].scnhdr.s_relptr = *file_cursor;
  452.           *file_cursor += external_reloc_size;
  453.           segment_info[idx].scnhdr.s_nreloc = nrelocs;
  454.         }
  455.       else
  456.         {
  457.           /* No relocs */
  458.           segment_info[idx].scnhdr.s_relptr = 0;
  459.         }
  460.     }
  461.     }
  462.   /* Set relocation_size field in file headers */
  463.   H_SET_RELOCATION_SIZE (h, *file_cursor - reloc_start, 0);
  464. }
  465.  
  466.  
  467. /* run through a frag chain and write out the data to go with it, fill
  468.    in the scnhdrs with the info on the file postions
  469. */
  470. static void
  471. DEFUN (fill_section, (abfd, h, file_cursor),
  472.        bfd * abfd AND
  473.        object_headers *h AND
  474.        unsigned long *file_cursor)
  475. {
  476.  
  477.   unsigned int i;
  478.   unsigned int paddr = 0;
  479.  
  480.   for (i = SEG_E0; i < SEG_UNKNOWN; i++)
  481.     {
  482.       unsigned int offset = 0;
  483.  
  484.       struct internal_scnhdr *s = &(segment_info[i].scnhdr);
  485.  
  486.       if (s->s_name[0])
  487.     {
  488.       fragS *frag = segment_info[i].frchainP->frch_root;
  489.       char *buffer;
  490.  
  491.       if (s->s_size == 0)
  492.         s->s_scnptr = 0;
  493.       else
  494.         {
  495.           buffer = xmalloc (s->s_size);
  496.           s->s_scnptr = *file_cursor;
  497.         }
  498.       know (s->s_paddr == paddr);
  499.  
  500.       if (strcmp (s->s_name, ".text") == 0)
  501.         s->s_flags |= STYP_TEXT;
  502.       else if (strcmp (s->s_name, ".data") == 0)
  503.         s->s_flags |= STYP_DATA;
  504.       else if (strcmp (s->s_name, ".bss") == 0)
  505.         {
  506.           s->s_scnptr = 0;
  507.           s->s_flags |= STYP_BSS;
  508. #ifndef TC_I386
  509. #ifndef TC_A29K
  510.           /* Apparently the SVR3 linker is confused by noload
  511.          sections.  So is the UDI mondfe program.  */
  512.           s->s_flags |= STYP_NOLOAD;
  513. #endif
  514. #endif
  515.         }
  516.       else if (strcmp (s->s_name, ".lit") == 0)
  517.         s->s_flags = STYP_LIT | STYP_TEXT;
  518.       else if (strcmp (s->s_name, ".init") == 0)
  519.         s->s_flags |= STYP_TEXT;
  520.       else if (strcmp (s->s_name, ".fini") == 0)
  521.         s->s_flags |= STYP_TEXT;
  522.       else if (strncmp (s->s_name, ".comment", 8) == 0)
  523.         s->s_flags |= STYP_INFO;
  524.  
  525.       while (frag)
  526.         {
  527.           unsigned int fill_size;
  528.           switch (frag->fr_type)
  529.         {
  530.         case rs_machine_dependent:
  531.           if (frag->fr_fix)
  532.             {
  533.               memcpy (buffer + frag->fr_address,
  534.                   frag->fr_literal,
  535.                   frag->fr_fix);
  536.               offset += frag->fr_fix;
  537.             }
  538.  
  539.           break;
  540.         case rs_fill:
  541.         case rs_align:
  542.         case rs_org:
  543.           if (frag->fr_fix)
  544.             {
  545.               memcpy (buffer + frag->fr_address,
  546.                   frag->fr_literal,
  547.                   frag->fr_fix);
  548.               offset += frag->fr_fix;
  549.             }
  550.  
  551.           fill_size = frag->fr_var;
  552.           if (fill_size)
  553.             {
  554.               unsigned int count;
  555.               unsigned int off = frag->fr_fix;
  556.               for (count = frag->fr_offset; count; count--)
  557.             {
  558.               if (fill_size < s->s_size)
  559.                 {
  560.                   memcpy (buffer + frag->fr_address + off,
  561.                       frag->fr_literal + frag->fr_fix,
  562.                       fill_size);
  563.                   off += fill_size;
  564.                   offset += fill_size;
  565.                 }
  566.             }
  567.             }
  568.           break;
  569.         case rs_broken_word:
  570.           break;
  571.         default:
  572.           abort ();
  573.         }
  574.           frag = frag->fr_next;
  575.         }
  576.  
  577.       if (s->s_size != 0)
  578.         {
  579.           if (s->s_scnptr != 0)
  580.         {
  581.           bfd_write (buffer, s->s_size, 1, abfd);
  582.           *file_cursor += s->s_size;
  583.         }
  584.           free (buffer);
  585.         }
  586.       paddr += s->s_size;
  587.     }
  588.     }
  589. }
  590.  
  591. /* Coff file generation & utilities */
  592.  
  593. static void
  594. DEFUN (coff_header_append, (abfd, h),
  595.        bfd * abfd AND
  596.        object_headers * h)
  597. {
  598.   unsigned int i;
  599.   char buffer[1000];
  600.   char buffero[1000];
  601.  
  602.   bfd_seek (abfd, 0, 0);
  603.  
  604. #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
  605.   H_SET_MAGIC_NUMBER (h, COFF_MAGIC);
  606.   H_SET_VERSION_STAMP (h, 0);
  607.   H_SET_ENTRY_POINT (h, 0);
  608.   H_SET_TEXT_START (h, segment_info[SEG_E0].frchainP->frch_root->fr_address);
  609.   H_SET_DATA_START (h, segment_info[SEG_E1].frchainP->frch_root->fr_address);
  610.   H_SET_SIZEOF_OPTIONAL_HEADER (h, bfd_coff_swap_aouthdr_out(abfd, &h->aouthdr,
  611.                                  buffero));
  612. #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
  613.   H_SET_SIZEOF_OPTIONAL_HEADER (h, 0);
  614. #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
  615.  
  616.   i = bfd_coff_swap_filehdr_out (abfd, &h->filehdr, buffer);
  617.  
  618.   bfd_write (buffer, i, 1, abfd);
  619.   bfd_write (buffero, H_GET_SIZEOF_OPTIONAL_HEADER (h), 1, abfd);
  620.  
  621.   for (i = SEG_E0; i < SEG_E9; i++)
  622.     {
  623.       if (segment_info[i].scnhdr.s_name[0])
  624.     {
  625.       unsigned int size =
  626.       bfd_coff_swap_scnhdr_out (abfd,
  627.                     &(segment_info[i].scnhdr),
  628.                     buffer);
  629.       bfd_write (buffer, size, 1, abfd);
  630.     }
  631.     }
  632. }
  633.  
  634.  
  635. char *
  636. DEFUN (symbol_to_chars, (abfd, where, symbolP),
  637.        bfd * abfd AND
  638.        char *where AND
  639.        symbolS * symbolP)
  640. {
  641.   unsigned int numaux = symbolP->sy_symbol.ost_entry.n_numaux;
  642.   unsigned int i;
  643.  
  644.   /* Turn any symbols with register attributes into abs symbols */
  645.   if (S_GET_SEGMENT (symbolP) == SEG_REGISTER)
  646.     {
  647.       S_SET_SEGMENT (symbolP, SEG_ABSOLUTE);
  648.     }
  649.   /* At the same time, relocate all symbols to their output value */
  650.  
  651.   S_SET_VALUE (symbolP,
  652.            segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_paddr
  653.            + S_GET_VALUE (symbolP));
  654.  
  655.   where += bfd_coff_swap_sym_out (abfd, &symbolP->sy_symbol.ost_entry,
  656.                   where);
  657.  
  658.   for (i = 0; i < numaux; i++)
  659.     {
  660.       where += bfd_coff_swap_aux_out (abfd,
  661.                       &symbolP->sy_symbol.ost_auxent[i],
  662.                       S_GET_DATA_TYPE (symbolP),
  663.                       S_GET_STORAGE_CLASS (symbolP),
  664.                       where);
  665.     }
  666.   return where;
  667.  
  668. }
  669.  
  670.  
  671. void
  672. obj_symbol_new_hook (symbolP)
  673.      symbolS *symbolP;
  674. {
  675.   char underscore = 0;        /* Symbol has leading _ */
  676.  
  677.   /* Effective symbol */
  678.   /* Store the pointer in the offset. */
  679.   S_SET_ZEROES (symbolP, 0L);
  680.   S_SET_DATA_TYPE (symbolP, T_NULL);
  681.   S_SET_STORAGE_CLASS (symbolP, 0);
  682.   S_SET_NUMBER_AUXILIARY (symbolP, 0);
  683.   /* Additional information */
  684.   symbolP->sy_symbol.ost_flags = 0;
  685.   /* Auxiliary entries */
  686.   bzero ((char *) &symbolP->sy_symbol.ost_auxent[0], AUXESZ);
  687.  
  688. #ifdef STRIP_UNDERSCORE
  689.   /* Remove leading underscore at the beginning of the symbol.
  690.      * This is to be compatible with the standard librairies.
  691.      */
  692.   if (*S_GET_NAME (symbolP) == '_')
  693.     {
  694.       underscore = 1;
  695.       S_SET_NAME (symbolP, S_GET_NAME (symbolP) + 1);
  696.     }                /* strip underscore */
  697. #endif /* STRIP_UNDERSCORE */
  698.  
  699.   if (S_IS_STRING (symbolP))
  700.     SF_SET_STRING (symbolP);
  701.   if (!underscore && S_IS_LOCAL (symbolP))
  702.     SF_SET_LOCAL (symbolP);
  703.  
  704.   return;
  705. }                /* obj_symbol_new_hook() */
  706.  
  707. /* stack stuff */
  708. stack *
  709. stack_init (chunk_size, element_size)
  710.      unsigned long chunk_size;
  711.      unsigned long element_size;
  712. {
  713.   stack *st;
  714.  
  715.   if ((st = (stack *) malloc (sizeof (stack))) == (stack *) 0)
  716.     return (stack *) 0;
  717.   if ((st->data = malloc (chunk_size)) == (char *) 0)
  718.     {
  719.       free (st);
  720.       return (stack *) 0;
  721.     }
  722.   st->pointer = 0;
  723.   st->size = chunk_size;
  724.   st->chunk_size = chunk_size;
  725.   st->element_size = element_size;
  726.   return st;
  727. }                /* stack_init() */
  728.  
  729. void
  730. stack_delete (st)
  731.      stack *st;
  732. {
  733.   free (st->data);
  734.   free (st);
  735. }
  736.  
  737. char *
  738. stack_push (st, element)
  739.      stack *st;
  740.      char *element;
  741. {
  742.   if (st->pointer + st->element_size >= st->size)
  743.     {
  744.       st->size += st->chunk_size;
  745.       if ((st->data = xrealloc (st->data, st->size)) == (char *) 0)
  746.     return (char *) 0;
  747.     }
  748.   memcpy (st->data + st->pointer, element, st->element_size);
  749.   st->pointer += st->element_size;
  750.   return st->data + st->pointer;
  751. }                /* stack_push() */
  752.  
  753. char *
  754. stack_pop (st)
  755.      stack *st;
  756. {
  757.   if ((st->pointer -= st->element_size) < 0)
  758.     {
  759.       st->pointer = 0;
  760.       return (char *) 0;
  761.     }
  762.  
  763.   return st->data + st->pointer;
  764. }
  765.  
  766. char *
  767. stack_top (st)
  768.      stack *st;
  769. {
  770.   return st->data + st->pointer - st->element_size;
  771. }
  772.  
  773.  
  774. /*
  775.  * Handle .ln directives.
  776.  */
  777.  
  778. static void
  779. obj_coff_ln ()
  780. {
  781.   int l;
  782.  
  783.   if (def_symbol_in_progress != NULL)
  784.     {
  785.       as_warn (".ln pseudo-op inside .def/.endef: ignored.");
  786.       demand_empty_rest_of_line ();
  787.       return;
  788.     }                /* wrong context */
  789.  
  790.   c_line_new (0,
  791.           obstack_next_free (&frags) - frag_now->fr_literal,
  792.           l = get_absolute_expression (),
  793.           frag_now);
  794. #ifndef NO_LISTING
  795.   {
  796.     extern int listing;
  797.  
  798.     if (listing)
  799.       {
  800.     listing_source_line (l + line_base - 1);
  801.       }
  802.  
  803.   }
  804. #endif
  805.   demand_empty_rest_of_line ();
  806.   return;
  807. }                /* obj_coff_line() */
  808.  
  809. /*
  810.  *            def()
  811.  *
  812.  * Handle .def directives.
  813.  *
  814.  * One might ask : why can't we symbol_new if the symbol does not
  815.  * already exist and fill it with debug information.  Because of
  816.  * the C_EFCN special symbol. It would clobber the value of the
  817.  * function symbol before we have a chance to notice that it is
  818.  * a C_EFCN. And a second reason is that the code is more clear this
  819.  * way. (at least I think it is :-).
  820.  *
  821.  */
  822.  
  823. #define SKIP_SEMI_COLON()    while (*input_line_pointer++ != ';')
  824. #define SKIP_WHITESPACES()    while (*input_line_pointer == ' ' || \
  825.                       *input_line_pointer == '\t') \
  826.                                          input_line_pointer++;
  827.  
  828. static void
  829. DEFUN (obj_coff_def, (what),
  830.        int what)
  831. {
  832.   char name_end;        /* Char after the end of name */
  833.   char *symbol_name;        /* Name of the debug symbol */
  834.   char *symbol_name_copy;    /* Temporary copy of the name */
  835.   unsigned int symbol_name_length;
  836.   /*$char*    directiveP;$ *//* Name of the pseudo opcode */
  837.   /*$char directive[MAX_DIRECTIVE];$ *//* Backup of the directive */
  838.   /*$char end = 0;$ *//* If 1, stop parsing */
  839.  
  840.   if (def_symbol_in_progress != NULL)
  841.     {
  842.       as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
  843.       demand_empty_rest_of_line ();
  844.       return;
  845.     }                /* if not inside .def/.endef */
  846.  
  847.   SKIP_WHITESPACES ();
  848.  
  849.   def_symbol_in_progress = (symbolS *) obstack_alloc (¬es, sizeof (*def_symbol_in_progress));
  850.   bzero (def_symbol_in_progress, sizeof (*def_symbol_in_progress));
  851.  
  852.   symbol_name = input_line_pointer;
  853.   name_end = get_symbol_end ();
  854.   symbol_name_length = strlen (symbol_name);
  855.   symbol_name_copy = xmalloc (symbol_name_length + 1);
  856.   strcpy (symbol_name_copy, symbol_name);
  857.  
  858.   /* Initialize the new symbol */
  859. #ifdef STRIP_UNDERSCORE
  860.   S_SET_NAME (def_symbol_in_progress, (*symbol_name_copy == '_'
  861.                        ? symbol_name_copy + 1
  862.                        : symbol_name_copy));
  863. #else /* STRIP_UNDERSCORE */
  864.   S_SET_NAME (def_symbol_in_progress, symbol_name_copy);
  865. #endif /* STRIP_UNDERSCORE */
  866.   /* free(symbol_name_copy); */
  867.   def_symbol_in_progress->sy_name_offset = ~0;
  868.   def_symbol_in_progress->sy_number = ~0;
  869.   def_symbol_in_progress->sy_frag = &zero_address_frag;
  870.  
  871.   if (S_IS_STRING (def_symbol_in_progress))
  872.     {
  873.       SF_SET_STRING (def_symbol_in_progress);
  874.     }                /* "long" name */
  875.  
  876.   *input_line_pointer = name_end;
  877.  
  878.   demand_empty_rest_of_line ();
  879.   return;
  880. }                /* obj_coff_def() */
  881.  
  882. unsigned int dim_index;
  883. static void
  884. DEFUN_VOID (obj_coff_endef)
  885. {
  886.   symbolS *symbolP = 0;
  887.   /* DIM BUG FIX sac@cygnus.com */
  888.   dim_index = 0;
  889.   if (def_symbol_in_progress == NULL)
  890.     {
  891.       as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
  892.       demand_empty_rest_of_line ();
  893.       return;
  894.     }                /* if not inside .def/.endef */
  895.  
  896.   /* Set the section number according to storage class. */
  897.   switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
  898.     {
  899.     case C_STRTAG:
  900.     case C_ENTAG:
  901.     case C_UNTAG:
  902.       SF_SET_TAG (def_symbol_in_progress);
  903.       /* intentional fallthrough */
  904.     case C_FILE:
  905.     case C_TPDEF:
  906.       SF_SET_DEBUG (def_symbol_in_progress);
  907.       S_SET_SEGMENT (def_symbol_in_progress, SEG_DEBUG);
  908.       break;
  909.  
  910.     case C_EFCN:
  911.       SF_SET_LOCAL (def_symbol_in_progress);    /* Do not emit this symbol. */
  912.       /* intentional fallthrough */
  913.     case C_BLOCK:
  914.       SF_SET_PROCESS (def_symbol_in_progress);    /* Will need processing before writing */
  915.       /* intentional fallthrough */
  916.     case C_FCN:
  917.       S_SET_SEGMENT (def_symbol_in_progress, SEG_E0);
  918.  
  919.       if (strcmp (S_GET_NAME (def_symbol_in_progress), ".bf") == 0)
  920.     {            /* .bf */
  921.       if (function_lineoff < 0)
  922.         {
  923.           fprintf (stderr, "`.bf' symbol without preceding function\n");
  924.         }            /* missing function symbol */
  925.       SA_GET_SYM_LNNOPTR (last_line_symbol) = function_lineoff;
  926.  
  927.       SF_SET_PROCESS (last_line_symbol);
  928.       function_lineoff = -1;
  929.     }
  930.       break;
  931.  
  932. #ifdef C_AUTOARG
  933.     case C_AUTOARG:
  934. #endif /* C_AUTOARG */
  935.     case C_AUTO:
  936.     case C_REG:
  937.     case C_MOS:
  938.     case C_MOE:
  939.     case C_MOU:
  940.     case C_ARG:
  941.     case C_REGPARM:
  942.     case C_FIELD:
  943.     case C_EOS:
  944.       SF_SET_DEBUG (def_symbol_in_progress);
  945.       S_SET_SEGMENT (def_symbol_in_progress, SEG_ABSOLUTE);
  946.       break;
  947.  
  948.     case C_EXT:
  949.     case C_STAT:
  950.     case C_LABEL:
  951.       /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
  952.       break;
  953.  
  954.     case C_USTATIC:
  955.     case C_EXTDEF:
  956.     case C_ULABEL:
  957.       as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress));
  958.       break;
  959.     }                /* switch on storage class */
  960.  
  961.   /* Now that we have built a debug symbol, try to find if we should
  962.      merge with an existing symbol or not.  If a symbol is C_EFCN or
  963.      SEG_ABSOLUTE or untagged SEG_DEBUG it never merges.  We also
  964.      don't merge labels, which are in a different namespace, nor
  965.      symbols which have not yet been defined since they are typically
  966.      unique, nor do we merge tags with non-tags.  */
  967.  
  968.   /* Two cases for functions.  Either debug followed by definition or
  969.      definition followed by debug.  For definition first, we will
  970.      merge the debug symbol into the definition.  For debug first, the
  971.      lineno entry MUST point to the definition function or else it
  972.      will point off into space when crawl_symbols() merges the debug
  973.      symbol into the real symbol.  Therefor, let's presume the debug
  974.      symbol is a real function reference. */
  975.  
  976.   /* FIXME-SOON If for some reason the definition label/symbol is
  977.      never seen, this will probably leave an undefined symbol at link
  978.      time. */
  979.  
  980.   if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
  981.       || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL
  982.       || (S_GET_SEGMENT (def_symbol_in_progress) == SEG_DEBUG
  983.       && !SF_GET_TAG (def_symbol_in_progress))
  984.       || S_GET_SEGMENT (def_symbol_in_progress) == SEG_ABSOLUTE
  985.       || def_symbol_in_progress->sy_forward != NULL
  986.       || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress), DO_NOT_STRIP)) == NULL
  987.       || (SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP)))
  988.     {
  989.       symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
  990.              &symbol_lastP);
  991.     }
  992.   else
  993.     {
  994.       /* This symbol already exists, merge the newly created symbol
  995.      into the This is not mandatory. The linker can handle
  996.      duplicate symbols correctly. But I guess that it save a *lot*
  997.      of space if the assembly file defines a lot of
  998.      symbols. [loic] */
  999.  
  1000.       /* The debug entry (def_symbol_in_progress) is merged into the
  1001.      previous definition.  */
  1002.  
  1003.       c_symbol_merge (def_symbol_in_progress, symbolP);
  1004.       /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
  1005.       def_symbol_in_progress = symbolP;
  1006.  
  1007.       if (SF_GET_FUNCTION (def_symbol_in_progress)
  1008.       || SF_GET_TAG (def_symbol_in_progress))
  1009.     {
  1010.       /* For functions, and tags, the symbol *must* be where the
  1011.          debug symbol appears.  Move the existing symbol to the
  1012.          current place. */
  1013.       /* If it already is at the end of the symbol list, do nothing */
  1014.       if (def_symbol_in_progress != symbol_lastP)
  1015.         {
  1016.           symbol_remove (def_symbol_in_progress, &symbol_rootP,
  1017.                  &symbol_lastP);
  1018.           symbol_append (def_symbol_in_progress, symbol_lastP,
  1019.                  &symbol_rootP, &symbol_lastP);
  1020.         }            /* if not already in place */
  1021.     }            /* if function */
  1022.     }                /* normal or mergable */
  1023.  
  1024.   if (SF_GET_TAG (def_symbol_in_progress)
  1025.       && symbol_find_base (S_GET_NAME (def_symbol_in_progress), DO_NOT_STRIP) == NULL)
  1026.     {
  1027.       tag_insert (S_GET_NAME (def_symbol_in_progress), def_symbol_in_progress);
  1028.     }
  1029.  
  1030.   if (SF_GET_FUNCTION (def_symbol_in_progress))
  1031.     {
  1032.       know (sizeof (def_symbol_in_progress) <= sizeof (long));
  1033.       function_lineoff
  1034.     = c_line_new (def_symbol_in_progress, 0, 0, &zero_address_frag);
  1035.  
  1036.       SF_SET_PROCESS (def_symbol_in_progress);
  1037.  
  1038.       if (symbolP == NULL)
  1039.     {
  1040.       /* That is, if this is the first time we've seen the
  1041.          function... */
  1042.       symbol_table_insert (def_symbol_in_progress);
  1043.     }            /* definition follows debug */
  1044.     }                /* Create the line number entry pointing to the function being defined */
  1045.  
  1046.   def_symbol_in_progress = NULL;
  1047.   demand_empty_rest_of_line ();
  1048.   return;
  1049. }
  1050.  
  1051. static void
  1052. DEFUN_VOID (obj_coff_dim)
  1053. {
  1054.   register int dim_index;
  1055.  
  1056.   if (def_symbol_in_progress == NULL)
  1057.     {
  1058.       as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
  1059.       demand_empty_rest_of_line ();
  1060.       return;
  1061.     }                /* if not inside .def/.endef */
  1062.  
  1063.   S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
  1064.  
  1065.   for (dim_index = 0; dim_index < DIMNUM; dim_index++)
  1066.     {
  1067.       SKIP_WHITESPACES ();
  1068.       SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index, get_absolute_expression ());
  1069.  
  1070.       switch (*input_line_pointer)
  1071.     {
  1072.  
  1073.     case ',':
  1074.       input_line_pointer++;
  1075.       break;
  1076.  
  1077.     default:
  1078.       as_warn ("badly formed .dim directive ignored");
  1079.       /* intentional fallthrough */
  1080.     case '\n':
  1081.     case ';':
  1082.       dim_index = DIMNUM;
  1083.       break;
  1084.     }            /* switch on following character */
  1085.     }                /* for each dimension */
  1086.  
  1087.   demand_empty_rest_of_line ();
  1088.   return;
  1089. }                /* obj_coff_dim() */
  1090.  
  1091. static void
  1092. obj_coff_line ()
  1093. {
  1094.   int this_base;
  1095.  
  1096.   if (def_symbol_in_progress == NULL)
  1097.     {
  1098.       obj_coff_ln ();
  1099.       return;
  1100.     }                /* if it looks like a stabs style line */
  1101.  
  1102.   this_base = get_absolute_expression ();
  1103.   if (this_base > line_base)
  1104.     {
  1105.       line_base = this_base;
  1106.     }
  1107.  
  1108.  
  1109. #ifndef NO_LISTING
  1110.   {
  1111.     extern int listing;
  1112.     if (listing && 0)
  1113.       {
  1114.     listing_source_line (line_base);
  1115.       }
  1116.   }
  1117. #endif
  1118.   S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
  1119.   SA_SET_SYM_LNNO (def_symbol_in_progress, line_base);
  1120.  
  1121.   demand_empty_rest_of_line ();
  1122.   return;
  1123. }                /* obj_coff_line() */
  1124.  
  1125. static void
  1126. obj_coff_size ()
  1127. {
  1128.   if (def_symbol_in_progress == NULL)
  1129.     {
  1130.       as_warn (".size pseudo-op used outside of .def/.endef ignored.");
  1131.       demand_empty_rest_of_line ();
  1132.       return;
  1133.     }                /* if not inside .def/.endef */
  1134.  
  1135.   S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
  1136.   SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
  1137.   demand_empty_rest_of_line ();
  1138.   return;
  1139. }                /* obj_coff_size() */
  1140.  
  1141. static void
  1142. obj_coff_scl ()
  1143. {
  1144.   if (def_symbol_in_progress == NULL)
  1145.     {
  1146.       as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
  1147.       demand_empty_rest_of_line ();
  1148.       return;
  1149.     }                /* if not inside .def/.endef */
  1150.  
  1151.   S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
  1152.   demand_empty_rest_of_line ();
  1153.   return;
  1154. }                /* obj_coff_scl() */
  1155.  
  1156. static void
  1157. obj_coff_tag ()
  1158. {
  1159.   char *symbol_name;
  1160.   char name_end;
  1161.  
  1162.   if (def_symbol_in_progress == NULL)
  1163.     {
  1164.       as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
  1165.       demand_empty_rest_of_line ();
  1166.       return;
  1167.     }                /* if not inside .def/.endef */
  1168.  
  1169.   S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
  1170.   symbol_name = input_line_pointer;
  1171.   name_end = get_symbol_end ();
  1172.  
  1173.   /* Assume that the symbol referred to by .tag is always defined. */
  1174.   /* This was a bad assumption.  I've added find_or_make. xoxorich. */
  1175.   SA_SET_SYM_TAGNDX (def_symbol_in_progress, (long) tag_find_or_make (symbol_name));
  1176.   if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
  1177.     {
  1178.       as_warn ("tag not found for .tag %s", symbol_name);
  1179.     }                /* not defined */
  1180.  
  1181.   SF_SET_TAGGED (def_symbol_in_progress);
  1182.   *input_line_pointer = name_end;
  1183.  
  1184.   demand_empty_rest_of_line ();
  1185.   return;
  1186. }                /* obj_coff_tag() */
  1187.  
  1188. static void
  1189. obj_coff_type ()
  1190. {
  1191.   if (def_symbol_in_progress == NULL)
  1192.     {
  1193.       as_warn (".type pseudo-op used outside of .def/.endef ignored.");
  1194.       demand_empty_rest_of_line ();
  1195.       return;
  1196.     }                /* if not inside .def/.endef */
  1197.  
  1198.   S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
  1199.  
  1200.   if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
  1201.       S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
  1202.     {
  1203.       SF_SET_FUNCTION (def_symbol_in_progress);
  1204.     }                /* is a function */
  1205.  
  1206.   demand_empty_rest_of_line ();
  1207.   return;
  1208. }                /* obj_coff_type() */
  1209.  
  1210. static void
  1211. obj_coff_val ()
  1212. {
  1213.   if (def_symbol_in_progress == NULL)
  1214.     {
  1215.       as_warn (".val pseudo-op used outside of .def/.endef ignored.");
  1216.       demand_empty_rest_of_line ();
  1217.       return;
  1218.     }                /* if not inside .def/.endef */
  1219.  
  1220.   if (is_name_beginner (*input_line_pointer))
  1221.     {
  1222.       char *symbol_name = input_line_pointer;
  1223.       char name_end = get_symbol_end ();
  1224.  
  1225.       if (!strcmp (symbol_name, "."))
  1226.     {
  1227.       def_symbol_in_progress->sy_frag = frag_now;
  1228.       S_SET_VALUE (def_symbol_in_progress, obstack_next_free (&frags) - frag_now->fr_literal);
  1229.       /* If the .val is != from the .def (e.g. statics) */
  1230.     }
  1231.       else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name))
  1232.     {
  1233.       def_symbol_in_progress->sy_forward = symbol_find_or_make (symbol_name);
  1234.  
  1235.       /* If the segment is undefined when the forward
  1236.                reference is solved, then copy the segment id
  1237.                from the forward symbol. */
  1238.       SF_SET_GET_SEGMENT (def_symbol_in_progress);
  1239.  
  1240.       /* FIXME: gcc can generate address expressions
  1241.          here in unusual cases (search for "obscure"
  1242.          in sdbout.c).  We just ignore the offset
  1243.          here, thus generating incorrect debugging
  1244.          information.  We ignore the rest of the
  1245.          line just below.  */
  1246.     }
  1247.       /* Otherwise, it is the name of a non debug symbol and
  1248.      its value will be calculated later. */
  1249.       *input_line_pointer = name_end;
  1250.  
  1251.       /* FIXME: this is to avoid an error message in the
  1252.      FIXME case mentioned just above.  */
  1253.       while (! is_end_of_line[*input_line_pointer])
  1254.     ++input_line_pointer;
  1255.     }
  1256.   else
  1257.     {
  1258.       S_SET_VALUE (def_symbol_in_progress, get_absolute_expression ());
  1259.     }                /* if symbol based */
  1260.  
  1261.   demand_empty_rest_of_line ();
  1262.   return;
  1263. }                /* obj_coff_val() */
  1264.  
  1265. /*
  1266.  * Maintain a list of the tagnames of the structres.
  1267.  */
  1268.  
  1269. static void
  1270. tag_init ()
  1271. {
  1272.   tag_hash = hash_new ();
  1273.   return;
  1274. }                /* tag_init() */
  1275.  
  1276. static void
  1277. tag_insert (name, symbolP)
  1278.      char *name;
  1279.      symbolS *symbolP;
  1280. {
  1281.   register char *error_string;
  1282.  
  1283.   if (*(error_string = hash_jam (tag_hash, name, (char *) symbolP)))
  1284.     {
  1285.       as_fatal ("Inserting \"%s\" into structure table failed: %s",
  1286.         name, error_string);
  1287.     }
  1288.   return;
  1289. }                /* tag_insert() */
  1290.  
  1291. static symbolS *
  1292. tag_find_or_make (name)
  1293.      char *name;
  1294. {
  1295.   symbolS *symbolP;
  1296.  
  1297.   if ((symbolP = tag_find (name)) == NULL)
  1298.     {
  1299.       symbolP = symbol_new (name,
  1300.                 SEG_UNKNOWN,
  1301.                 0,
  1302.                 &zero_address_frag);
  1303.  
  1304.       tag_insert (S_GET_NAME (symbolP), symbolP);
  1305.     }                /* not found */
  1306.  
  1307.   return (symbolP);
  1308. }                /* tag_find_or_make() */
  1309.  
  1310. static symbolS *
  1311. tag_find (name)
  1312.      char *name;
  1313. {
  1314. #ifdef STRIP_UNDERSCORE
  1315.   if (*name == '_')
  1316.     name++;
  1317. #endif /* STRIP_UNDERSCORE */
  1318.   return ((symbolS *) hash_find (tag_hash, name));
  1319. }                /* tag_find() */
  1320.  
  1321. void
  1322. obj_read_begin_hook ()
  1323. {
  1324.   /* These had better be the same.  Usually 18 bytes. */
  1325. #ifndef BFD_HEADERS
  1326.   know (sizeof (SYMENT) == sizeof (AUXENT));
  1327.   know (SYMESZ == AUXESZ);
  1328. #endif
  1329.   tag_init ();
  1330.  
  1331.   return;
  1332. }                /* obj_read_begin_hook() */
  1333.  
  1334. /* This function runs through the symbol table and puts all the
  1335.    externals onto another chain */
  1336.  
  1337. /* The chain of externals */
  1338. symbolS *symbol_externP = NULL;
  1339. symbolS *symbol_extern_lastP = NULL;
  1340.  
  1341. stack *block_stack;
  1342. symbolS *last_functionP = NULL;
  1343. symbolS *last_tagP;
  1344.  
  1345. static unsigned int
  1346. DEFUN_VOID (yank_symbols)
  1347. {
  1348.   symbolS *symbolP;
  1349.   unsigned int symbol_number = 0;
  1350.   unsigned int last_file_symno = 0;
  1351.  
  1352.   for (symbolP = symbol_rootP;
  1353.        symbolP;
  1354.        symbolP = symbolP ? symbol_next (symbolP) : symbol_rootP)
  1355.     {
  1356.       if (!SF_GET_DEBUG (symbolP))
  1357.     {
  1358.       /* Debug symbols do not need all this rubbish */
  1359.       symbolS *real_symbolP;
  1360.  
  1361.       /* L* and C_EFCN symbols never merge. */
  1362.       if (!SF_GET_LOCAL (symbolP)
  1363.           && S_GET_STORAGE_CLASS (symbolP) != C_LABEL
  1364.           && symbolP->sy_forward == NULL
  1365.           && (real_symbolP = symbol_find_base (S_GET_NAME (symbolP), DO_NOT_STRIP))
  1366.           && real_symbolP != symbolP)
  1367.         {
  1368.           /* FIXME-SOON: where do dups come from?
  1369.          Maybe tag references before definitions? xoxorich. */
  1370.           /* Move the debug data from the debug symbol to the
  1371.          real symbol. Do NOT do the oposite (i.e. move from
  1372.          real symbol to debug symbol and remove real symbol from the
  1373.          list.) Because some pointers refer to the real symbol
  1374.          whereas no pointers refer to the debug symbol. */
  1375.           c_symbol_merge (symbolP, real_symbolP);
  1376.           /* Replace the current symbol by the real one */
  1377.           /* The symbols will never be the last or the first
  1378.          because : 1st symbol is .file and 3 last symbols are
  1379.          .text, .data, .bss */
  1380.           symbol_remove (real_symbolP, &symbol_rootP, &symbol_lastP);
  1381.           symbol_insert (real_symbolP, symbolP, &symbol_rootP, &symbol_lastP);
  1382.           symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
  1383.           symbolP = real_symbolP;
  1384.         }            /* if not local but dup'd */
  1385.  
  1386.       if (flagseen['R'] && (S_GET_SEGMENT (symbolP) == SEG_E1))
  1387.         {
  1388.           S_SET_SEGMENT (symbolP, SEG_E0);
  1389.         }            /* push data into text */
  1390.  
  1391.       S_SET_VALUE (symbolP,
  1392.                S_GET_VALUE (symbolP) + symbolP->sy_frag->fr_address);
  1393.  
  1394.       if (!S_IS_DEFINED (symbolP) && !SF_GET_LOCAL (symbolP))
  1395.         {
  1396.           S_SET_EXTERNAL (symbolP);
  1397.         }
  1398.       else if (S_GET_STORAGE_CLASS (symbolP) == C_NULL)
  1399.         {
  1400.           if (S_GET_SEGMENT (symbolP) == SEG_E0)
  1401.         {
  1402.           S_SET_STORAGE_CLASS (symbolP, C_LABEL);
  1403.         }
  1404.           else
  1405.         {
  1406.           S_SET_STORAGE_CLASS (symbolP, C_STAT);
  1407.         }
  1408.         }
  1409.  
  1410.       /* Mainly to speed up if not -g */
  1411.       if (SF_GET_PROCESS (symbolP))
  1412.         {
  1413.           /* Handle the nested blocks auxiliary info. */
  1414.           if (S_GET_STORAGE_CLASS (symbolP) == C_BLOCK)
  1415.         {
  1416.           if (!strcmp (S_GET_NAME (symbolP), ".bb"))
  1417.             stack_push (block_stack, (char *) &symbolP);
  1418.           else
  1419.             {        /* .eb */
  1420.               register symbolS *begin_symbolP;
  1421.               begin_symbolP = *(symbolS **) stack_pop (block_stack);
  1422.               if (begin_symbolP == (symbolS *) 0)
  1423.             as_warn ("mismatched .eb");
  1424.               else
  1425.             SA_SET_SYM_ENDNDX (begin_symbolP, symbol_number + 2);
  1426.             }
  1427.         }
  1428.           /* If we are able to identify the type of a function, and we
  1429.            are out of a function (last_functionP == 0) then, the
  1430.            function symbol will be associated with an auxiliary
  1431.            entry. */
  1432.           if (last_functionP == (symbolS *) 0 &&
  1433.           SF_GET_FUNCTION (symbolP))
  1434.         {
  1435.           last_functionP = symbolP;
  1436.  
  1437.           if (S_GET_NUMBER_AUXILIARY (symbolP) < 1)
  1438.             {
  1439.               S_SET_NUMBER_AUXILIARY (symbolP, 1);
  1440.             }        /* make it at least 1 */
  1441.  
  1442.           /* Clobber possible stale .dim information. */
  1443. #if 0
  1444.           /* Iffed out by steve - this fries the lnnoptr info too */
  1445.           bzero (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen,
  1446.              sizeof (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen));
  1447. #endif
  1448.         }
  1449.           /* The C_FCN doesn't need any additional information.  I
  1450.          don't even know if this is needed for sdb. But the
  1451.          standard assembler generates it, so...  */
  1452.           if (S_GET_STORAGE_CLASS (symbolP) == C_EFCN)
  1453.         {
  1454.           if (last_functionP == (symbolS *) 0)
  1455.             as_fatal ("C_EFCN symbol out of scope");
  1456.           SA_SET_SYM_FSIZE (last_functionP,
  1457.                     (long) (S_GET_VALUE (symbolP) -
  1458.                         S_GET_VALUE (last_functionP)));
  1459.           SA_SET_SYM_ENDNDX (last_functionP, symbol_number);
  1460.           last_functionP = (symbolS *) 0;
  1461.         }
  1462.         }
  1463.     }
  1464.       else if (SF_GET_TAG (symbolP))
  1465.     {
  1466.       /* First descriptor of a structure must point to
  1467.            the first slot after the structure description. */
  1468.       last_tagP = symbolP;
  1469.  
  1470.     }
  1471.       else if (S_GET_STORAGE_CLASS (symbolP) == C_EOS)
  1472.     {
  1473.       /* +2 take in account the current symbol */
  1474.       SA_SET_SYM_ENDNDX (last_tagP, symbol_number + 2);
  1475.     }
  1476.       else if (S_GET_STORAGE_CLASS (symbolP) == C_FILE)
  1477.     {
  1478.       if (S_GET_VALUE (symbolP))
  1479.         {
  1480.           S_SET_VALUE (symbolP, last_file_symno);
  1481.           last_file_symno = symbol_number;
  1482.         }            /* no one points at the first .file symbol */
  1483.     }            /* if debug or tag or eos or file */
  1484.  
  1485.       /* We must put the external symbols apart. The loader
  1486.      does not bomb if we do not. But the references in
  1487.      the endndx field for a .bb symbol are not corrected
  1488.      if an external symbol is removed between .bb and .be.
  1489.      I.e in the following case :
  1490.      [20] .bb endndx = 22
  1491.      [21] foo external
  1492.      [22] .be
  1493.      ld will move the symbol 21 to the end of the list but
  1494.      endndx will still be 22 instead of 21. */
  1495.  
  1496.  
  1497.       if (SF_GET_LOCAL (symbolP))
  1498.     {
  1499.       /* remove C_EFCN and LOCAL (L...) symbols */
  1500.       /* next pointer remains valid */
  1501.       symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
  1502.  
  1503.     }
  1504.       else if (!S_IS_DEFINED (symbolP)
  1505.            && !S_IS_DEBUG (symbolP)
  1506.            && !SF_GET_STATICS (symbolP) &&
  1507.            S_GET_STORAGE_CLASS (symbolP) == C_EXT)
  1508.     {            /* C_EXT && !SF_GET_FUNCTION(symbolP))  */
  1509.       /* if external, Remove from the list */
  1510.       symbolS *hold = symbol_previous (symbolP);
  1511.  
  1512.       symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
  1513.       symbol_clear_list_pointers (symbolP);
  1514.       symbol_append (symbolP, symbol_extern_lastP, &symbol_externP, &symbol_extern_lastP);
  1515.       symbolP = hold;
  1516.     }
  1517.       else
  1518.     {
  1519.       if (SF_GET_STRING (symbolP))
  1520.         {
  1521.           symbolP->sy_name_offset = string_byte_count;
  1522.           string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
  1523.         }
  1524.       else
  1525.         {
  1526.           symbolP->sy_name_offset = 0;
  1527.         }            /* fix "long" names */
  1528.  
  1529.       symbolP->sy_number = symbol_number;
  1530.       symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
  1531.     }            /* if local symbol */
  1532.     }                /* traverse the symbol list */
  1533.   return symbol_number;
  1534.  
  1535. }
  1536.  
  1537.  
  1538. static unsigned int
  1539. DEFUN_VOID (glue_symbols)
  1540. {
  1541.   unsigned int symbol_number = 0;
  1542.   symbolS *symbolP;
  1543.   for (symbolP = symbol_externP; symbol_externP;)
  1544.     {
  1545.       symbolS *tmp = symbol_externP;
  1546.  
  1547.       /* append */
  1548.       symbol_remove (tmp, &symbol_externP, &symbol_extern_lastP);
  1549.       symbol_append (tmp, symbol_lastP, &symbol_rootP, &symbol_lastP);
  1550.  
  1551.       /* and process */
  1552.       if (SF_GET_STRING (tmp))
  1553.     {
  1554.       tmp->sy_name_offset = string_byte_count;
  1555.       string_byte_count += strlen (S_GET_NAME (tmp)) + 1;
  1556.     }
  1557.       else
  1558.     {
  1559.       tmp->sy_name_offset = 0;
  1560.     }            /* fix "long" names */
  1561.  
  1562.       tmp->sy_number = symbol_number;
  1563.       symbol_number += 1 + S_GET_NUMBER_AUXILIARY (tmp);
  1564.     }                /* append the entire extern chain */
  1565.   return symbol_number;
  1566.  
  1567. }
  1568.  
  1569. static unsigned int
  1570. DEFUN_VOID (tie_tags)
  1571. {
  1572.   unsigned int symbol_number = 0;
  1573.  
  1574.   symbolS *symbolP;
  1575.   for (symbolP = symbol_rootP; symbolP; symbolP =
  1576.        symbol_next (symbolP))
  1577.     {
  1578.       symbolP->sy_number = symbol_number;
  1579.  
  1580.  
  1581.  
  1582.       if (SF_GET_TAGGED (symbolP))
  1583.     {
  1584.       SA_SET_SYM_TAGNDX
  1585.         (symbolP,
  1586.          ((symbolS *) SA_GET_SYM_TAGNDX (symbolP))->sy_number);
  1587.     }
  1588.  
  1589.       symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
  1590.     }
  1591.   return symbol_number;
  1592.  
  1593. }
  1594.  
  1595. static void
  1596. DEFUN (crawl_symbols, (h, abfd),
  1597.        object_headers *h AND
  1598.        bfd * abfd)
  1599. {
  1600.  
  1601.   unsigned int i;
  1602.   symbolS *symbolP;
  1603.  
  1604.   /* Initialize the stack used to keep track of the matching .bb .be */
  1605.  
  1606.   block_stack = stack_init (512, sizeof (symbolS *));
  1607.   /* JF deal with forward references first... */
  1608.   for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
  1609.     if (symbolP->sy_forward)
  1610.       {
  1611.     S_SET_VALUE (symbolP, (S_GET_VALUE (symbolP)
  1612.                    + S_GET_VALUE (symbolP->sy_forward)
  1613.                    + symbolP->sy_forward->sy_frag->fr_address));
  1614.     if (SF_GET_GET_SEGMENT (symbolP))
  1615.       S_SET_SEGMENT (symbolP, S_GET_SEGMENT (symbolP->sy_forward));
  1616.       }
  1617.  
  1618.   /* The symbol list should be ordered according to the following sequence
  1619.    * order :
  1620.    * . .file symbol
  1621.    * . debug entries for functions
  1622.    * . fake symbols for the sections, including.text .data and .bss
  1623.    * . defined symbols
  1624.    * . undefined symbols
  1625.    * But this is not mandatory. The only important point is to put the
  1626.    * undefined symbols at the end of the list.
  1627.    */
  1628.  
  1629.   if (symbol_rootP == NULL
  1630.       || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
  1631.     {
  1632.       c_dot_file_symbol ("fake");
  1633.     }
  1634.   /* Is there a .file symbol ? If not insert one at the beginning. */
  1635.  
  1636.   /*
  1637.    * Build up static symbols for the sections, they are filled in later
  1638.    */
  1639.  
  1640.  
  1641.   for (i = SEG_E0; i < SEG_E9; i++)
  1642.     {
  1643.       if (segment_info[i].scnhdr.s_name[0])
  1644.     {
  1645.       char name[9];
  1646.  
  1647.       strncpy (name, segment_info[i].scnhdr.s_name, 8);
  1648.       name[8] = '\0';
  1649.       segment_info[i].dot = c_section_symbol (name, i - SEG_E0 + 1);
  1650.     }
  1651.     }
  1652.  
  1653.  
  1654.   /* Take all the externals out and put them into another chain */
  1655.   H_SET_SYMBOL_TABLE_SIZE (h, yank_symbols ());
  1656.   /* Take the externals and glue them onto the end.*/
  1657.   H_SET_SYMBOL_TABLE_SIZE (h, H_GET_SYMBOL_COUNT (h) + glue_symbols ());
  1658.  
  1659.   H_SET_SYMBOL_TABLE_SIZE (h, tie_tags ());
  1660.   know (symbol_externP == NULL);
  1661.   know (symbol_extern_lastP == NULL);
  1662.  
  1663.   return;
  1664. }
  1665.  
  1666. /*
  1667.  * Find strings by crawling along symbol table chain.
  1668.  */
  1669.  
  1670. void
  1671. DEFUN (w_strings, (where),
  1672.        char *where)
  1673. {
  1674.   symbolS *symbolP;
  1675.  
  1676.   /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
  1677.   md_number_to_chars (where, string_byte_count, sizeof (string_byte_count));
  1678.   where += sizeof (string_byte_count);
  1679.   for (symbolP = symbol_rootP;
  1680.        symbolP;
  1681.        symbolP = symbol_next (symbolP))
  1682.     {
  1683.       unsigned int size;
  1684.  
  1685.       if (SF_GET_STRING (symbolP))
  1686.     {
  1687.       size = strlen (S_GET_NAME (symbolP)) + 1;
  1688.  
  1689.       memcpy (where, S_GET_NAME (symbolP), size);
  1690.       where += size;
  1691.  
  1692.     }
  1693.     }
  1694.  
  1695. }
  1696.  
  1697. static void
  1698. DEFUN (do_linenos_for, (abfd, h, file_cursor),
  1699.        bfd * abfd AND
  1700.        object_headers * h AND
  1701.        unsigned long *file_cursor)
  1702. {
  1703.   unsigned int idx;
  1704.   unsigned long start = *file_cursor;
  1705.  
  1706.   for (idx = SEG_E0; idx < SEG_E9; idx++)
  1707.     {
  1708.       segment_info_type *s = segment_info + idx;
  1709.  
  1710.  
  1711.       if (s->scnhdr.s_nlnno != 0)
  1712.     {
  1713.       struct lineno_list *line_ptr;
  1714.  
  1715.       struct external_lineno *buffer =
  1716.       (struct external_lineno *) xmalloc (s->scnhdr.s_nlnno * LINESZ);
  1717.  
  1718.       struct external_lineno *dst = buffer;
  1719.  
  1720.       /* Run through the table we've built and turn it into its external
  1721.      form, take this chance to remove duplicates */
  1722.  
  1723.       for (line_ptr = s->lineno_list_head;
  1724.            line_ptr != (struct lineno_list *) NULL;
  1725.            line_ptr = line_ptr->next)
  1726.         {
  1727.  
  1728.           if (line_ptr->line.l_lnno == 0)
  1729.         {
  1730.           /* Turn a pointer to a symbol into the symbols' index */
  1731.           line_ptr->line.l_addr.l_symndx =
  1732.             ((symbolS *) line_ptr->line.l_addr.l_symndx)->sy_number;
  1733.         }
  1734.           else
  1735.         {
  1736.           line_ptr->line.l_addr.l_paddr += ((struct frag *) (line_ptr->frag))->fr_address;
  1737.         }
  1738.  
  1739.  
  1740.           (void) bfd_coff_swap_lineno_out (abfd, &(line_ptr->line), dst);
  1741.           dst++;
  1742.  
  1743.         }
  1744.  
  1745.       s->scnhdr.s_lnnoptr = *file_cursor;
  1746.  
  1747.       bfd_write (buffer, 1, s->scnhdr.s_nlnno * LINESZ, abfd);
  1748.       free (buffer);
  1749.  
  1750.       *file_cursor += s->scnhdr.s_nlnno * LINESZ;
  1751.     }
  1752.     }
  1753.   H_SET_LINENO_SIZE (h, *file_cursor - start);
  1754. }
  1755.  
  1756.  
  1757. /* Now we run through the list of frag chains in a segment and
  1758.    make all the subsegment frags appear at the end of the
  1759.    list, as if the seg 0 was extra long */
  1760.  
  1761. static void
  1762. DEFUN_VOID (remove_subsegs)
  1763. {
  1764.   unsigned int i;
  1765.  
  1766.   for (i = SEG_E0; i < SEG_UNKNOWN; i++)
  1767.     {
  1768.       frchainS *head = segment_info[i].frchainP;
  1769.       fragS dummy;
  1770.       fragS *prev_frag = &dummy;
  1771.  
  1772.       while (head && head->frch_seg == i)
  1773.     {
  1774.       prev_frag->fr_next = head->frch_root;
  1775.       prev_frag = head->frch_last;
  1776.       head = head->frch_next;
  1777.     }
  1778.       prev_frag->fr_next = 0;
  1779.     }
  1780. }
  1781.  
  1782. int machine;
  1783. int coff_flags;
  1784. extern void
  1785. DEFUN_VOID (write_object_file)
  1786. {
  1787.   int i;
  1788.   struct frchain *frchain_ptr;
  1789.  
  1790.   object_headers headers;
  1791.   unsigned long file_cursor;
  1792.   bfd *abfd;
  1793.   unsigned int addr;
  1794.   abfd = bfd_openw (out_file_name, TARGET_FORMAT);
  1795.  
  1796.  
  1797.   if (abfd == 0)
  1798.     {
  1799.       as_perror ("FATAL: Can't create %s", out_file_name);
  1800.       exit (42);
  1801.     }
  1802.   bfd_set_format (abfd, bfd_object);
  1803.   bfd_set_arch_mach (abfd, BFD_ARCH, machine);
  1804.  
  1805.   string_byte_count = 4;
  1806.  
  1807.   for (frchain_ptr = frchain_root;
  1808.        frchain_ptr != (struct frchain *) NULL;
  1809.        frchain_ptr = frchain_ptr->frch_next)
  1810.     {
  1811.       /* Run through all the sub-segments and align them up. Also close any
  1812.            open frags. We tack a .fill onto the end of the frag chain so
  1813.            that any .align's size can be worked by looking at the next
  1814.            frag */
  1815.  
  1816.       subseg_new (frchain_ptr->frch_seg, frchain_ptr->frch_subseg);
  1817. #ifndef SUB_SEGMENT_ALIGN
  1818. #define SUB_SEGMENT_ALIGN(SEG) 1
  1819. #endif
  1820.       frag_align (SUB_SEGMENT_ALIGN (now_seg), NOP_OPCODE);
  1821.       frag_wane (frag_now);
  1822.       frag_now->fr_fix = 0;
  1823.       know (frag_now->fr_next == NULL);
  1824.     }
  1825.  
  1826.  
  1827.   remove_subsegs ();
  1828.  
  1829.  
  1830.   for (i = SEG_E0; i < SEG_UNKNOWN; i++)
  1831.     {
  1832.       relax_segment (segment_info[i].frchainP->frch_root, i);
  1833.     }
  1834.  
  1835.   H_SET_NUMBER_OF_SECTIONS (&headers, 0);
  1836.  
  1837.   /* Find out how big the sections are, and set the addresses.  */
  1838.   addr = 0;
  1839.   for (i = SEG_E0; i < SEG_UNKNOWN; i++)
  1840.     {
  1841.       long size;
  1842.  
  1843.       segment_info[i].scnhdr.s_paddr = addr;
  1844.       segment_info[i].scnhdr.s_vaddr = addr;
  1845.  
  1846.       if (segment_info[i].scnhdr.s_name[0])
  1847.     {
  1848.       H_SET_NUMBER_OF_SECTIONS (&headers,
  1849.                     H_GET_NUMBER_OF_SECTIONS (&headers) + 1);
  1850.     }
  1851.  
  1852.       size = size_section (abfd, i);
  1853.       addr += size;
  1854.  
  1855.       if (i == SEG_E0)
  1856.     H_SET_TEXT_SIZE (&headers, size);
  1857.       else if (i == SEG_E1)
  1858.     H_SET_DATA_SIZE (&headers, size);
  1859.       else if (i == SEG_E2)
  1860.     H_SET_BSS_SIZE (&headers, size);
  1861.     }
  1862.  
  1863.   /* Turn the gas native symbol table shape into a coff symbol table */
  1864.   crawl_symbols (&headers, abfd);
  1865.  
  1866.   if (string_byte_count == 4)
  1867.     string_byte_count = 0;
  1868.  
  1869.   H_SET_STRING_SIZE (&headers, string_byte_count);
  1870.  
  1871. #if !defined(TC_H8300) && !defined(TC_Z8K) 
  1872.   for (i = SEG_E0; i < SEG_UNKNOWN; i++)
  1873.     {
  1874.       fixup_mdeps (segment_info[i].frchainP->frch_root, &headers, i);
  1875.       fixup_segment (&segment_info[i], i);
  1876.     }
  1877. #endif
  1878.  
  1879.   file_cursor = H_GET_TEXT_FILE_OFFSET (&headers);
  1880.  
  1881.   bfd_seek (abfd, file_cursor, 0);
  1882.  
  1883.   /* Plant the data */
  1884.  
  1885.   fill_section (abfd, &headers, &file_cursor);
  1886.  
  1887.   do_relocs_for (abfd, &headers, &file_cursor);
  1888.  
  1889.   do_linenos_for (abfd, &headers, &file_cursor);
  1890.  
  1891.   H_SET_FILE_MAGIC_NUMBER (&headers, COFF_MAGIC);
  1892. #ifndef OBJ_COFF_OMIT_TIMESTAMP
  1893.   H_SET_TIME_STAMP (&headers, (long)time((long*)0));
  1894. #else
  1895.   H_SET_TIME_STAMP (&headers, 0);
  1896. #endif
  1897.  
  1898. #ifdef KEEP_RELOC_INFO
  1899.   H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) |
  1900.               COFF_FLAGS | coff_flags));
  1901. #else
  1902.   H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers)     ? 0 : F_LNNO)   |
  1903.               (H_GET_RELOCATION_SIZE(&headers) ? 0 : F_RELFLG) |
  1904.               COFF_FLAGS | coff_flags));
  1905. #endif    
  1906.  
  1907.   {
  1908.     unsigned int symtable_size = H_GET_SYMBOL_TABLE_SIZE (&headers);
  1909.     char *buffer1 = xmalloc (symtable_size + string_byte_count + 1);
  1910.     char *ptr = buffer1;
  1911.     H_SET_SYMBOL_TABLE_POINTER (&headers, bfd_tell (abfd));
  1912.     w_symbols (abfd, buffer1, symbol_rootP);
  1913.     if (string_byte_count > 0)
  1914.       w_strings (buffer1 + symtable_size);
  1915.     bfd_write (buffer1, 1, symtable_size + string_byte_count, abfd);
  1916.     free (buffer1);
  1917.   }
  1918.  
  1919.   coff_header_append (abfd, &headers);
  1920.  
  1921.   if (bfd_close_all_done (abfd) == false)
  1922.     as_fatal ("Can't close %s: %s", out_file_name,
  1923.           bfd_errmsg (bfd_error));
  1924. }
  1925.  
  1926.  
  1927. static void
  1928. DEFUN (change_to_section, (name, len, exp),
  1929.        char *name AND
  1930.        unsigned int len AND
  1931.        unsigned int exp)
  1932. {
  1933.   unsigned int i;
  1934.   /* Find out if we've already got a section of this name etc */
  1935.   for (i = SEG_E0; i < SEG_E9 && segment_info[i].scnhdr.s_name[0]; i++)
  1936.     {
  1937.       if (strncmp (segment_info[i].scnhdr.s_name, name, len) == 0)
  1938.     {
  1939.       subseg_new (i, exp);
  1940.       return;
  1941.     }
  1942.     }
  1943.   /* No section, add one */
  1944.   strncpy (segment_info[i].scnhdr.s_name, name, 8);
  1945.   segment_info[i].scnhdr.s_flags = STYP_REG;
  1946.   subseg_new (i, exp);
  1947. }
  1948.  
  1949. /*
  1950.  * implement the .section pseudo op:
  1951.  *    .section name {, "flags"}
  1952.  *                ^         ^
  1953.  *                |         +--- optional flags: 'b' for bss
  1954.  *                |                              'i' for info
  1955.  *                +-- section name               'l' for lib
  1956.  *                                               'n' for noload
  1957.  *                                               'o' for over
  1958.  *                                               'w' for data
  1959.  *                                               'x' for text
  1960.  * But if the argument is not a quoted string, treat it as a
  1961.  * subsegment number.
  1962.  */
  1963.  
  1964. void
  1965. DEFUN_VOID (obj_coff_section)
  1966. {
  1967.   /* Strip out the section name */
  1968.   char *section_name;
  1969.   char *section_name_end;
  1970.   char c;
  1971.   int argp;
  1972.   unsigned int len;
  1973.   unsigned int exp;
  1974.   long flags;
  1975.  
  1976.   section_name = input_line_pointer;
  1977.   c = get_symbol_end ();
  1978.   section_name_end = input_line_pointer;
  1979.  
  1980.   len = section_name_end - section_name;
  1981.   input_line_pointer++;
  1982.   SKIP_WHITESPACE ();
  1983.  
  1984.   argp = 0;
  1985.   if (c == ',')
  1986.     argp = 1;
  1987.   else if (*input_line_pointer == ',')
  1988.     {
  1989.       argp = 1;
  1990.       ++input_line_pointer;
  1991.       SKIP_WHITESPACE ();
  1992.     }
  1993.  
  1994.   exp = 0;
  1995.   flags = 0;
  1996.   if (argp)
  1997.     {
  1998.       if (*input_line_pointer != '"')
  1999.     exp = get_absolute_expression ();
  2000.       else
  2001.     {
  2002.       ++input_line_pointer;
  2003.       while (*input_line_pointer != '"'
  2004.          && ! is_end_of_line[*input_line_pointer])
  2005.         {
  2006.           switch (*input_line_pointer)
  2007.         {
  2008.         case 'b': flags |= STYP_BSS;    break;
  2009.         case 'i': flags |= STYP_INFO;   break;
  2010.         case 'l': flags |= STYP_LIB;    break;
  2011.         case 'n': flags |= STYP_NOLOAD; break;
  2012.         case 'o': flags |= STYP_OVER;   break;
  2013.         case 'w': flags |= STYP_DATA;   break;
  2014.         case 'x': flags |= STYP_TEXT;   break;
  2015.         default:
  2016.           as_warn("unknown section attribute '%c'",
  2017.               *input_line_pointer);
  2018.           break;
  2019.         }
  2020.           ++input_line_pointer;
  2021.         }
  2022.       if (*input_line_pointer == '"')
  2023.         ++input_line_pointer;
  2024.     }
  2025.     }
  2026.  
  2027.   change_to_section (section_name, len, exp);
  2028.  
  2029.   segment_info[now_seg].scnhdr.s_flags |= flags;
  2030.  
  2031.   *section_name_end = c;
  2032. }
  2033.  
  2034.  
  2035. static void
  2036. obj_coff_text ()
  2037. {
  2038.   change_to_section (".text", 5, get_absolute_expression ());
  2039. }
  2040.  
  2041.  
  2042. static void
  2043. obj_coff_data ()
  2044. {
  2045.   change_to_section (".data", 5, get_absolute_expression ());
  2046. }
  2047.  
  2048. static void
  2049. obj_coff_bss()
  2050. {
  2051.   if (*input_line_pointer == '\n')    /* .bss         */
  2052.     change_to_section(".bss",4, get_absolute_expression());
  2053.   else                    /* .bss id,expr        */
  2054.     obj_coff_lcomm();
  2055. }
  2056.  
  2057. static void
  2058. obj_coff_ident()
  2059. {
  2060.   segT current_seg = now_seg;        /* save current seg    */
  2061.   subsegT current_subseg = now_subseg;
  2062.   change_to_section (".comment", 8, 0);    /* .comment seg        */
  2063.   stringer (1);                /* read string        */
  2064.   subseg_new (current_seg, current_subseg);    /* restore current seg    */
  2065. }
  2066.  
  2067. void
  2068. c_symbol_merge (debug, normal)
  2069.      symbolS *debug;
  2070.      symbolS *normal;
  2071. {
  2072.   S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
  2073.   S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
  2074.  
  2075.   if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
  2076.     {
  2077.       S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
  2078.     }                /* take the most we have */
  2079.  
  2080.   if (S_GET_NUMBER_AUXILIARY (debug) > 0)
  2081.     {
  2082.       memcpy ((char *) &normal->sy_symbol.ost_auxent[0], (char *) &debug->sy_symbol.ost_auxent[0], S_GET_NUMBER_AUXILIARY (debug) * AUXESZ);
  2083.     }                /* Move all the auxiliary information */
  2084.  
  2085.   /* Move the debug flags. */
  2086.   SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
  2087. }                /* c_symbol_merge() */
  2088.  
  2089. static int
  2090. DEFUN (c_line_new, (symbol, paddr, line_number, frag),
  2091.        symbolS * symbol AND
  2092.        long paddr AND
  2093.        unsigned short line_number AND
  2094.        fragS * frag)
  2095. {
  2096.   struct lineno_list *new_line =
  2097.   (struct lineno_list *) xmalloc (sizeof (struct lineno_list));
  2098.  
  2099.   segment_info_type *s = segment_info + now_seg;
  2100.   new_line->line.l_lnno = line_number;
  2101.  
  2102.   if (line_number == 0)
  2103.     {
  2104.       last_line_symbol = symbol;
  2105.       new_line->line.l_addr.l_symndx = (long) symbol;
  2106.     }
  2107.   else
  2108.     {
  2109.       new_line->line.l_addr.l_paddr = paddr;
  2110.     }
  2111.  
  2112.   new_line->frag = (char *) frag;
  2113.   new_line->next = (struct lineno_list *) NULL;
  2114.  
  2115.  
  2116.   if (s->lineno_list_head == (struct lineno_list *) NULL)
  2117.     {
  2118.       s->lineno_list_head = new_line;
  2119.     }
  2120.   else
  2121.     {
  2122.       s->lineno_list_tail->next = new_line;
  2123.     }
  2124.   s->lineno_list_tail = new_line;
  2125.   return LINESZ * s->scnhdr.s_nlnno++;
  2126. }
  2127.  
  2128. void
  2129. c_dot_file_symbol (filename)
  2130.      char *filename;
  2131. {
  2132.   symbolS *symbolP;
  2133.  
  2134.   symbolP = symbol_new (".file",
  2135.             SEG_DEBUG,
  2136.             0,
  2137.             &zero_address_frag);
  2138.  
  2139.   S_SET_STORAGE_CLASS (symbolP, C_FILE);
  2140.   S_SET_NUMBER_AUXILIARY (symbolP, 1);
  2141.   SA_SET_FILE_FNAME (symbolP, filename);
  2142. #ifndef NO_LISTING
  2143.   {
  2144.     extern int listing;
  2145.     if (listing)
  2146.       {
  2147.     listing_source_file (filename);
  2148.       }
  2149.  
  2150.   }
  2151.  
  2152. #endif
  2153.   SF_SET_DEBUG (symbolP);
  2154.   S_SET_VALUE (symbolP, (long) previous_file_symbol);
  2155.  
  2156.   previous_file_symbol = symbolP;
  2157.  
  2158.   /* Make sure that the symbol is first on the symbol chain */
  2159.   if (symbol_rootP != symbolP)
  2160.     {
  2161.       if (symbolP == symbol_lastP)
  2162.     {
  2163.       symbol_lastP = symbol_lastP->sy_previous;
  2164.     }            /* if it was the last thing on the list */
  2165.  
  2166.       symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
  2167.       symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
  2168.       symbol_rootP = symbolP;
  2169.     }                /* if not first on the list */
  2170.  
  2171. }                /* c_dot_file_symbol() */
  2172.  
  2173. /*
  2174.  * Build a 'section static' symbol.
  2175.  */
  2176.  
  2177. symbolS *
  2178. c_section_symbol (name, idx)
  2179.      char *name;
  2180.      int idx;
  2181. {
  2182.   symbolS *symbolP;
  2183.  
  2184.   symbolP = symbol_new (name, idx,
  2185.             0,
  2186.             &zero_address_frag);
  2187.  
  2188.   S_SET_STORAGE_CLASS (symbolP, C_STAT);
  2189.   S_SET_NUMBER_AUXILIARY (symbolP, 1);
  2190.  
  2191.   SF_SET_STATICS (symbolP);
  2192.  
  2193.   return symbolP;
  2194. }                /* c_section_symbol() */
  2195.  
  2196. static void
  2197. DEFUN (w_symbols, (abfd, where, symbol_rootP),
  2198.        bfd * abfd AND
  2199.        char *where AND
  2200.        symbolS * symbol_rootP)
  2201. {
  2202.   symbolS *symbolP;
  2203.   unsigned int i;
  2204.  
  2205.   /* First fill in those values we have only just worked out */
  2206.   for (i = SEG_E0; i < SEG_E9; i++)
  2207.     {
  2208.       symbolP = segment_info[i].dot;
  2209.       if (symbolP)
  2210.     {
  2211.  
  2212.       SA_SET_SCN_SCNLEN (symbolP, segment_info[i].scnhdr.s_size);
  2213.       SA_SET_SCN_NRELOC (symbolP, segment_info[i].scnhdr.s_nreloc);
  2214.       SA_SET_SCN_NLINNO (symbolP, segment_info[i].scnhdr.s_nlnno);
  2215.  
  2216.     }
  2217.     }
  2218.  
  2219.   /*
  2220.      * Emit all symbols left in the symbol chain.
  2221.      */
  2222.   for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
  2223.     {
  2224.       /* Used to save the offset of the name. It is used to point
  2225.            to the string in memory but must be a file offset. */
  2226.       register char *temp;
  2227.  
  2228.       tc_coff_symbol_emit_hook (symbolP);
  2229.  
  2230.       temp = S_GET_NAME (symbolP);
  2231.       if (SF_GET_STRING (symbolP))
  2232.     {
  2233.       S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
  2234.       S_SET_ZEROES (symbolP, 0);
  2235.     }
  2236.       else
  2237.     {
  2238.       bzero (symbolP->sy_symbol.ost_entry.n_name, SYMNMLEN);
  2239.       strncpy (symbolP->sy_symbol.ost_entry.n_name, temp, SYMNMLEN);
  2240.     }
  2241.       where = symbol_to_chars (abfd, where, symbolP);
  2242.       S_SET_NAME (symbolP, temp);
  2243.     }
  2244.  
  2245. }                /* w_symbols() */
  2246.  
  2247. static void
  2248. DEFUN_VOID (obj_coff_lcomm)
  2249. {
  2250.   char *name;
  2251.   char c;
  2252.   int temp;
  2253.   char *p;
  2254.  
  2255.   symbolS *symbolP;
  2256.   name = input_line_pointer;
  2257.  
  2258.   c = get_symbol_end ();
  2259.   p = input_line_pointer;
  2260.   *p = c;
  2261.   SKIP_WHITESPACE ();
  2262.   if (*input_line_pointer != ',')
  2263.     {
  2264.       as_bad ("Expected comma after name");
  2265.       ignore_rest_of_line ();
  2266.       return;
  2267.     }
  2268.   if (*input_line_pointer == '\n')
  2269.     {
  2270.       as_bad ("Missing size expression");
  2271.       return;
  2272.     }
  2273.   input_line_pointer++;
  2274.   if ((temp = get_absolute_expression ()) < 0)
  2275.     {
  2276.       as_warn ("lcomm length (%d.) <0! Ignored.", temp);
  2277.       ignore_rest_of_line ();
  2278.       return;
  2279.     }
  2280.   *p = 0;
  2281.  
  2282.   symbolP = symbol_find_or_make(name);
  2283.  
  2284.   if (S_GET_SEGMENT(symbolP) == SEG_UNKNOWN &&
  2285.       S_GET_VALUE(symbolP) == 0)
  2286.     {
  2287.       if (! need_pass_2)
  2288.     {
  2289.       char *p;
  2290.       segT current_seg = now_seg;     /* save current seg     */
  2291.       subsegT current_subseg = now_subseg;
  2292.  
  2293.       subseg_new (SEG_E2, 1);
  2294.       symbolP->sy_frag = frag_now;
  2295.       p = frag_var(rs_org, 1, 1, (relax_substateT)0, symbolP,
  2296.                temp, (char *)0);
  2297.       *p = 0;
  2298.       subseg_new (current_seg, current_subseg); /* restore current seg */
  2299.       S_SET_SEGMENT(symbolP, SEG_E2);
  2300.       S_SET_STORAGE_CLASS(symbolP, C_STAT);
  2301.     }
  2302.     }
  2303.   else
  2304.     as_bad("Symbol %s already defined", name);
  2305.  
  2306.   demand_empty_rest_of_line();
  2307. }
  2308.  
  2309. static void
  2310. DEFUN (fixup_mdeps, (frags, h, this_segment),
  2311.        fragS * frags AND
  2312.        object_headers * h AND
  2313.        segT this_segment)
  2314. {
  2315.   subseg_change (this_segment, 0);
  2316.   while (frags)
  2317.     {
  2318.       switch (frags->fr_type)
  2319.     {
  2320.     case rs_align:
  2321.     case rs_org:
  2322.       frags->fr_type = rs_fill;
  2323.       frags->fr_offset =
  2324.         (frags->fr_next->fr_address - frags->fr_address - frags->fr_fix);
  2325.       break;
  2326.     case rs_machine_dependent:
  2327.       md_convert_frag (h, frags);
  2328.       frag_wane (frags);
  2329.       break;
  2330.     default:
  2331.       ;
  2332.     }
  2333.       frags = frags->fr_next;
  2334.     }
  2335. }
  2336.  
  2337. #if 1
  2338. static void
  2339. DEFUN (fixup_segment, (segP, this_segment_type),
  2340.        segment_info_type * segP AND
  2341.        segT this_segment_type)
  2342. {
  2343.   register fixS * fixP;
  2344.   register symbolS *add_symbolP;
  2345.   register symbolS *sub_symbolP;
  2346.   register long add_number;
  2347.   register int size;
  2348.   register char *place;
  2349.   register long where;
  2350.   register char pcrel;
  2351.   register fragS *fragP;
  2352.   register segT add_symbol_segment = SEG_ABSOLUTE;
  2353.  
  2354.  
  2355.   for (fixP = segP->fix_root; fixP; fixP = fixP->fx_next)
  2356.     {
  2357.       fragP = fixP->fx_frag;
  2358.       know (fragP);
  2359.       where = fixP->fx_where;
  2360.       place = fragP->fr_literal + where;
  2361.       size = fixP->fx_size;
  2362.       add_symbolP = fixP->fx_addsy;
  2363. #ifdef TC_I960
  2364.       if (fixP->fx_callj && TC_S_IS_CALLNAME (add_symbolP))
  2365.     {
  2366.       /* Relocation should be done via the
  2367.            associated 'bal' entry point
  2368.            symbol. */
  2369.  
  2370.       if (!TC_S_IS_BALNAME (tc_get_bal_of_call (add_symbolP)))
  2371.         {
  2372.           as_bad ("No 'bal' entry point for leafproc %s",
  2373.               S_GET_NAME (add_symbolP));
  2374.           continue;
  2375.         }
  2376.       fixP->fx_addsy = add_symbolP = tc_get_bal_of_call (add_symbolP);
  2377.     }            /* callj relocation */
  2378. #endif
  2379.       sub_symbolP = fixP->fx_subsy;
  2380.       add_number = fixP->fx_offset;
  2381.       pcrel = fixP->fx_pcrel;
  2382.  
  2383.       if (add_symbolP)
  2384.     {
  2385.       add_symbol_segment = S_GET_SEGMENT (add_symbolP);
  2386.     }            /* if there is an addend */
  2387.  
  2388.       if (sub_symbolP)
  2389.     {
  2390.       if (!add_symbolP)
  2391.         {
  2392.           /* Its just -sym */
  2393.           if (S_GET_SEGMENT (sub_symbolP) != SEG_ABSOLUTE)
  2394.         {
  2395.           as_bad ("Negative of non-absolute symbol %s", S_GET_NAME (sub_symbolP));
  2396.         }        /* not absolute */
  2397.  
  2398.           add_number -= S_GET_VALUE (sub_symbolP);
  2399.           fixP->fx_subsy = 0;
  2400.  
  2401.           /* if sub_symbol is in the same segment that add_symbol
  2402.                and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
  2403.         }
  2404.       else if ((S_GET_SEGMENT (sub_symbolP) == add_symbol_segment)
  2405.            && (SEG_NORMAL (add_symbol_segment)
  2406.                || (add_symbol_segment == SEG_ABSOLUTE)))
  2407.         {
  2408.           /* Difference of 2 symbols from same segment. */
  2409.           /* Can't make difference of 2 undefineds: 'value' means */
  2410.           /* something different for N_UNDF. */
  2411. #ifdef TC_I960
  2412.           /* Makes no sense to use the difference of 2 arbitrary symbols
  2413.              as the target of a call instruction.  */
  2414.           if (fixP->fx_callj)
  2415.         {
  2416.           as_bad ("callj to difference of 2 symbols");
  2417.         }
  2418. #endif /* TC_I960 */
  2419.           add_number += S_GET_VALUE (add_symbolP) -
  2420.         S_GET_VALUE (sub_symbolP);
  2421.  
  2422.           add_symbolP = NULL;
  2423.           fixP->fx_addsy = NULL;
  2424.         }
  2425.       else
  2426.         {
  2427.           /* Different segments in subtraction. */
  2428.           know (!(S_IS_EXTERNAL (sub_symbolP) && (S_GET_SEGMENT (sub_symbolP) == SEG_ABSOLUTE)));
  2429.  
  2430.           if ((S_GET_SEGMENT (sub_symbolP) == SEG_ABSOLUTE))
  2431.         {
  2432.           add_number -= S_GET_VALUE (sub_symbolP);
  2433.         }
  2434.           else
  2435.         {
  2436.           as_bad ("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %d.",
  2437.               segment_name (S_GET_SEGMENT (sub_symbolP)),
  2438.                S_GET_NAME (sub_symbolP), fragP->fr_address + where);
  2439.         }        /* if absolute */
  2440.         }
  2441.     }            /* if sub_symbolP */
  2442.  
  2443.       if (add_symbolP)
  2444.     {
  2445.       if (add_symbol_segment == this_segment_type && pcrel)
  2446.         {
  2447.           /*
  2448.            * This fixup was made when the symbol's segment was
  2449.            * SEG_UNKNOWN, but it is now in the local segment.
  2450.            * So we know how to do the address without relocation.
  2451.            */
  2452. #ifdef TC_I960
  2453.           /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
  2454.            * in which cases it modifies *fixP as appropriate.  In the case
  2455.            * of a 'calls', no further work is required, and *fixP has been
  2456.            * set up to make the rest of the code below a no-op.
  2457.            */
  2458.           reloc_callj (fixP);
  2459. #endif /* TC_I960 */
  2460.  
  2461.           add_number += S_GET_VALUE (add_symbolP);
  2462.           add_number -= md_pcrel_from (fixP);
  2463. #ifdef TC_I386
  2464.           /* On the 386 we must adjust by the segment
  2465.          vaddr as well.  Ian Taylor.  */
  2466.           add_number -= segP->scnhdr.s_vaddr;
  2467. #endif
  2468.           pcrel = 0;    /* Lie. Don't want further pcrel processing. */
  2469.           fixP->fx_addsy = NULL;    /* No relocations please. */
  2470.         }
  2471.       else
  2472.         {
  2473.           switch (add_symbol_segment)
  2474.         {
  2475.         case SEG_ABSOLUTE:
  2476. #ifdef TC_I960
  2477.           reloc_callj (fixP);    /* See comment about reloc_callj() above*/
  2478. #endif /* TC_I960 */
  2479.           add_number += S_GET_VALUE (add_symbolP);
  2480.           fixP->fx_addsy = NULL;
  2481.           add_symbolP = NULL;
  2482.           break;
  2483.         default:
  2484.  
  2485. #ifdef TC_A29K
  2486.           /* This really should be handled in the linker, but
  2487.              backward compatibility forbids.  */
  2488.           add_number += S_GET_VALUE (add_symbolP);
  2489. #else
  2490.           add_number += S_GET_VALUE (add_symbolP) +
  2491.             segment_info[S_GET_SEGMENT (add_symbolP)].scnhdr.s_paddr;
  2492. #endif
  2493.           break;
  2494.  
  2495.         case SEG_UNKNOWN:
  2496. #ifdef TC_I960
  2497.           if ((int) fixP->fx_bit_fixP == 13)
  2498.             {
  2499.               /* This is a COBR instruction.  They have only a
  2500.                * 13-bit displacement and are only to be used
  2501.                * for local branches: flag as error, don't generate
  2502.                * relocation.
  2503.                */
  2504.               as_bad ("can't use COBR format with external label");
  2505.               fixP->fx_addsy = NULL;    /* No relocations please. */
  2506.               continue;
  2507.             }        /* COBR */
  2508. #endif /* TC_I960 */
  2509. #ifdef TC_I386
  2510.           /* 386 COFF uses a peculiar format in
  2511.              which the value of a common symbol is
  2512.              stored in the .text segment (I've
  2513.              checked this on SVR3.2 and SCO 3.2.2)
  2514.              Ian Taylor <ian@cygnus.com>.  */
  2515.           if (S_IS_COMMON (add_symbolP))
  2516.             add_number += S_GET_VALUE (add_symbolP);
  2517. #endif
  2518.           break;
  2519.  
  2520.  
  2521.         }        /* switch on symbol seg */
  2522.         }            /* if not in local seg */
  2523.     }            /* if there was a + symbol */
  2524.  
  2525.       if (pcrel)
  2526.     {
  2527.       add_number -= md_pcrel_from (fixP);
  2528.       if (add_symbolP == 0)
  2529.         {
  2530.           fixP->fx_addsy = &abs_symbol;
  2531.         }            /* if there's an add_symbol */
  2532. #ifdef TC_I386
  2533.       /* On the 386 we must adjust by the segment vaddr
  2534.          as well.  Ian Taylor.  */
  2535.       add_number -= segP->scnhdr.s_vaddr;
  2536. #endif
  2537.     }            /* if pcrel */
  2538.  
  2539.       if (!fixP->fx_bit_fixP)
  2540.     {
  2541.       if ((size == 1 &&
  2542.       (add_number & ~0xFF) && ((add_number & ~0xFF) != (-1 & ~0xFF))) ||
  2543.           (size == 2 &&
  2544.            (add_number & ~0xFFFF) && ((add_number & ~0xFFFF) != (-1 & ~0xFFFF))))
  2545.         {
  2546.           as_bad ("Value of %d too large for field of %d bytes at 0x%x",
  2547.               add_number, size, fragP->fr_address + where);
  2548.         }            /* generic error checking */
  2549. #ifdef WARN_SIGNED_OVERFLOW_WORD
  2550.       /* Warn if a .word value is too large when treated as
  2551.          a signed number.  We already know it is not too
  2552.          negative.  This is to catch over-large switches
  2553.          generated by gcc on the 68k.  */
  2554.       if (!flagseen['J']
  2555.           && size == 2
  2556.           && add_number > 0x7fff)
  2557.         as_bad ("Signed .word overflow; switch may be too large; %d at 0x%x",
  2558.             add_number, fragP->fr_address + where);
  2559. #endif
  2560.     }            /* not a bit fix */
  2561.       /* once this fix has been applied, we don't have to output anything
  2562.        nothing more need be done -*/
  2563.       md_apply_fix (fixP, add_number);
  2564.     }                /* For each fixS in this segment. */
  2565. }                /* fixup_segment() */
  2566.  
  2567. #endif
  2568.